
import 'package:date_picker_plus/date_picker_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_crud_test_amir_rabbani/core/utils/date_format.dart';
import 'package:flutter_crud_test_amir_rabbani/core/widgets/base_stateless.dart';
import 'package:flutter_crud_test_amir_rabbani/core/widgets/clickable_container.dart';

class DateInput extends BaseStateless {
  String? hint, title;
  TextEditingController? controller;
  double? fontSize;
  Function(DateTime t)? onSubmitted;
  DateTime? value;
  List<String>? autofillHints;

  DateInput(
      {this.hint,
      this.title,
      this.controller,
      this.fontSize = 15,
      this.onSubmitted,
      this.value,
      this.autofillHints,
      Key? key})
      : super(key: key);

  @override
  Widget buildState(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        if (title != null)
          Padding(
            padding: const EdgeInsets.only(right: 10, bottom: 10),
            child: Text(
              title ?? '',
              style: textTheme.bodyLarge,
            ),
          ),
        ClickableContainer(
          padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
          border: Border.all(
            color:
                Theme.of(context).inputDecorationTheme.border!.borderSide.color,
          ),
          onTap: () async {
            DateTime? date = await showDatePickerDialog(
              context: context,
              initialDate: DateTime(2022, 10, 10),
              minDate: DateTime(2020, 10, 10),
              maxDate: DateTime(2024, 10, 30),
              width: 300,
              height: 300,
              currentDate: DateTime(2022, 10, 15),
              selectedDate: DateTime(2022, 10, 16),
              currentDateDecoration: const BoxDecoration(),
              currentDateTextStyle: const TextStyle(),
              daysOfTheWeekTextStyle: const TextStyle(),
              disabledCellsTextStyle: const TextStyle(),
              enabledCellsDecoration: const BoxDecoration(),
              enabledCellsTextStyle: const TextStyle(),
              initialPickerType: PickerType.days,
              selectedCellDecoration: const BoxDecoration(),
              selectedCellTextStyle: const TextStyle(),
              leadingDateTextStyle: const TextStyle(),
              slidersColor: Colors.lightBlue,
              highlightColor: Colors.redAccent,
              slidersSize: 20,
              splashColor: Colors.lightBlueAccent,
              splashRadius: 40,
              centerLeadingDate: true,
            );
            if (date != null && onSubmitted != null) onSubmitted!(date);
          },
          height: 48,
          width: double.infinity,
          borderRadius: BorderRadius.circular(8),
          child: Text(value?.toCustomFormat() ?? (hint ?? '')),
        ),
      ],
    );
  }
}
